export default {
  data() {
    return {
      specilist: [],
      // 品牌
      hotBrandList: [], //品牌热门品牌
      scrollTop: 0,
      Brandlist: [],
      indexlist: [],
      addtoView: '', //定位abc
      Serieslist: [], //系列
      displacement: [], //排量
      modelyear: [], //年款
      // 车子
      carInfo: {
        brand_Id: 0,
        brand_Name: '',
        car_Type_Id: 0,
        car_Type_Name: '',
        car_Id: 0,
        car_Name: '',
        displacement: '',
        yeartype: '',
      }, //选择的车辆信息
      // indicatorStyle: `height: ${Math.round(
      //   uni.getSystemInfoSync().screenWidth / (750 / 100)
      // )}px;`, //设置选择器中间选中框的样式
      Configurationlist: [], //配置list-页面渲染显示
      Configuname: '', //配置name-页面渲染显示
      typeid: '120', //传入的值，不同的页面传入不同的数字，页面显示不同的区域
      selectShow: 1, //控制列表显示隐藏 1品牌，2系列，3排量，4年款，5车子
      // CarsaddtoView: '', //车子定位
      pageLoading: false, //初始化加载效果
    }
  },

  // 监听返回
  onBackPress(e) {
    const pageOut = {
      110: 0,
      120: 1,
    }
    if (e.from === 'navigateBack') {
      return false //监听返回onBackPress一定要return
    }
    if (this.selectShow !== pageOut[this.typeid]) {
      this.selectShow -= 1
      return true
    } else {
      return false
    }
  },

  // vue实例加载完成
  created() {
    this.getHotBrandList() //热门品牌
    this.GetCarBrandList()
  },

  methods: {
    // 品牌配置
    async GetCarBrandList() {
      try {
        const res = await this.$api.common.GetCarBrandList()
        this.Brandlist = res.data
        this.Brandlist.forEach((item, index) => {
          this.indexlist.push(item.initial)
        })
      } catch (err) {
        console.log(err)
      }
      this.pageLoading = true
    },

    // 车型配置
    async GetCarModelAndConfigList(typeid) {
      try {
        let data = {
          Bid: typeid,
        }
        const res = await this.$api.afterSales.getCarTypeLists(data)
        this.Serieslist = res.data
      } catch (err) {
        console.log(err)
      }
    },

    // 排量配置
    async getcarTypeDisplacementLists(typeid) {
      try {
        let data = {
          carTypeid: typeid,
        }
        const res = await this.$api.afterSales.getcarTypeDisplacementLists(data)
        this.displacement = res.data
      } catch (err) {
        console.log(err)
      }
    },

    //年款配置
    async getCarList(data) {
      try {
        const res = await this.$api.afterSales.getCarList({ ...data })
        this.modelyear = res.data
      } catch (err) {
        console.log(err)
      }
    },

    //选择回退步骤
    backStep(i) {
      this.selectShow = i
    },

    // 品牌
    // 楼层定位
    addressToView(event) {
      var id = event.currentTarget.dataset.id
      this.addtoView = id
    },

    //选择品牌 type 0 热门品牌 1 品牌列表
    searchBrand(data, type) {
      if (type) {
        this.$set(this.carInfo, 'brand_Id', data.bid)
        this.$set(this.carInfo, 'brand_Name', data.brand)
        //车型配置接口
        this.GetCarModelAndConfigList(data.bid)
      } else {
        this.$set(this.carInfo, 'brand_Id', data.brandId)
        this.$set(this.carInfo, 'brand_Name', data.branName)
        //车型配置接口
        this.GetCarModelAndConfigList(data.brandId)
      }
      this.selectShow = 2
    },

    //热门品牌
    getHotBrandList() {
      this.$api.afterSales
        .getHotCarBrandList({
          type: 0,
        })
        .then((res) => {
          console.log(res)
          if (res.data.length) {
            this.hotBrandList = res.data
          }
        })
        .catch((e) => {
          console.log(e)
        })
    },

    //选择了系列
    seriesbtn(type) {
      this.$set(this.carInfo, 'car_Type_Id', type.carTypeId)
      this.$set(this.carInfo, 'car_Type_Name', type.carTypeName)
      this.selectShow = 3
      //排量配置接口
      this.getcarTypeDisplacementLists(type.carTypeId)
    },

    //选择了排量
    sdisplacementbtn(type) {
      this.$set(this.carInfo, 'displacement', type.displacement)
      this.selectShow = 4
      //年款配置
      this.getCarList(type)
    },

    //年款
    modelyearbtn(type, index) {
      this.$set(this.carInfo, 'yeartype', type.data)
      this.selectShow = 5
      this.Configurationlist = this.modelyear[index].list
    },

    // 车子
    //配置赋值
    Configbtn(type) {
      this.$set(this.carInfo, 'car_Name', type.name)
      this.$set(this.carInfo, 'car_Id', type.id)
      uni.$emit('specifAll', this.carInfo)
      this.selectShow = 0
      uni.navigateBack()
    },
  },
}
